index.ts 924 B

123456789101112131415161718192021222324252627
  1. import { createClient } from '@supabase/supabase-js'
  2. import { NextApiRequest, NextApiResponse } from 'next'
  3. import apiWrapper from '@/lib/api/apiWrapper'
  4. const briven = createClient(process.env.BRIVEN_URL!, process.env.BRIVEN_SERVICE_KEY!)
  5. export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
  6. async function handler(req: NextApiRequest, res: NextApiResponse) {
  7. const { method } = req
  8. switch (method) {
  9. case 'POST':
  10. return handlePost(req, res)
  11. default:
  12. res.setHeader('Allow', ['POST'])
  13. res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
  14. }
  15. }
  16. const handlePost = async (req: NextApiRequest, res: NextApiResponse) => {
  17. const { data, error } = await briven.auth.admin.createUser(req.body)
  18. if (error) return res.status(400).json({ error: { message: error.message } })
  19. return res.status(200).json(data.user)
  20. }